package com.alinesno.cloud.portal.auto.constants;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;

import com.alinesno.cloud.portal.auto.entity.AutoTaskEntity;

public class CommonPath {

	/**
	 * 获取构建的路径地址 
	 * @return
	 */
	public static String autoHome() {
		String userHome = AutoConstants.Path.USER_HOME ; 
        String path = System.getProperty(userHome)  + File.separator + AutoConstants.Path.AUTO_HOME ; 
		return path ; 
	}

	/**
	 * 获取当前生成的报告 
	 * @param e
	 * @return
	 * @throws IOException 
	 */
	public static String getReportPath(AutoTaskEntity e) throws IOException {
		
		File f = new File(File.separator + e.getId()+
				File.separator+e.getTaskVersion()+
				File.separator+"target"+
				File.separator+"gatling") ; 
		
		String lastRunPath = CommonPath.autoHome() + f.getAbsoluteFile()+File.separator+"lastRun.txt" ; 
		String lastRunReportPath = FileUtils.readFileToString(new File(lastRunPath)) ; 

		String reportPath = File.separator+AutoConstants.Path.REPORT + 
				f.getAbsolutePath() + 
				File.separator +lastRunReportPath.trim() + 
				File.separator + AutoConstants.Path.HTML_INDEX ; 
		
		return reportPath ;
	}

	/**
	 * 生成新的scala文件
	 * @param jobParentPath
	 * @return
	 */
	public static String scalaFilePath(String jobParentPath) {
		String path = jobParentPath + 
				
				File.separator + "src" + 
				File.separator + "test" + 
				File.separator + "scala" + 
				File.separator + "task" + 
				File.separator + "GatlingTask_"+System.currentTimeMillis()+".scala" ; 
				
		return path ;
	}
	
}
